const Koa = require('koa');
const app =new Koa();
const Router= require("koa-router");
const router=new Router();
const parser =require('koa-bodyparser');
const cors = require('koa2-cors');
app.use(parser());
app.use(cors());

router.post('/login',(ctx,next)=>{
    const body=ctx.request.body;
    console.log(body)
    if(body.loginName===null || body.loginPsd===null){
        console.log('ss')
        ctx.body={isok:false}
    }else{
        ctx.body={isok:true}
    }
    
})
router.post('/isWorking',(ctx,next)=>{
    const isWorking=ctx.request.body;
    console.log(isWorking)
    if(isWorking.isworking){
        ctx.body={
            message:"正在工作"
        }
    }else{
        ctx.body={
            message:'正在休息'
        }
    }
    
})
app.use(router.routes())

app.listen(3000,()=>{
    console.log("this is a Koa serve")
})